﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuickTweet.Models;
using QuickTweet.Common;
using System.Windows.Input;
using System.Windows.Data;
using QuickTweet.Common.Commanding;

namespace QuickTweet.ViewModels
{
    public class EditAccountViewModel : ViewModelBase
    {
        #region Properties

        public ICommand OKCommand { get; private set; }
        public ICommand CancelCommand { get; private set; }

        private string accountName;
        public string AccountName
        {
            get
            {
                return accountName;
            }
            set
            {
                if (UpdateProperty(value, ref accountName))
                    OnPropertyChanged("AccountName");
            }
        }

        private string twitterID;
        public string TwitterID
        {
            get
            {
                return twitterID;
            }
            set
            {
                if (UpdateProperty(value, ref twitterID))
                    OnPropertyChanged("TwitterID");
            }
        }

        private bool canClose;
        public bool CanClose
        {
            get
            {
                return canClose;
            }
            set
            {
                if (UpdateProperty(value, ref canClose))
                    OnPropertyChanged("CanClose");
            }
        }

        #endregion

        private TwitterAccount account;

        public EditAccountViewModel(TwitterAccount account)
        {
            this.account = account;

            CanClose = true;
            OKCommand = new DelegateCommand(args => Save(args),this.CreateBinding("CanClose"));
            CancelCommand = new DelegateCommand((args) => DialogResult = false);
        }

        private void Save(object parameter)
        {
            account.Name = accountName;
            account.TwitterID = twitterID;
            DialogResult = true;
        }
    }
}
